/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.sgw.runner;

/**
 *
 * @author paine
 */
public class RunEntry {
    private RunType runType;
    private float   distance;
    private int     hours;
    private int     minutes;
    private int     seconds;
    private int     pace;
    private int     totalSeconds;
    
    public RunEntry() {
    }
    
    public RunEntry(RunType runType, float   distance, int     hours,
                                      int     minutes, int     seconds) {
        this.runType  = runType;
        this.distance = distance;
        this.hours    = hours;
        this.minutes  = minutes;
        this.seconds  = seconds;
    }

    public float getDistance() {
        return distance;
    }

    public void setDistance(float distance) {
        this.distance = distance;
    }

    public int getHours() {
        return hours;
    }

    public void setHours(int hours) {
        this.hours = hours;
    }

    public int getMinutes() {
        return minutes;
    }

    public void setMinutes(int minutes) {
        this.minutes = minutes;
    }

    public int getPace() {
        return (int)(getTotalSeconds() / distance);
    }

    public RunType getRunType() {
        return runType;
    }

    public void setRunType(RunType runType) {
        this.runType = runType;
    }

    public int getSeconds() {
        return seconds;
    }

    public void setSeconds(int seconds) {
        this.seconds = seconds;
    }

    public void setTotalSeconds(int totalSeconds) {
        this.totalSeconds = totalSeconds;
    }
    
    public int getTotalSeconds() {
        if (totalSeconds > 0)
            return totalSeconds;
        else
            return ( (hours * 3600) + (minutes * 60) + seconds );
    }

    // TODO - Refactor below mthods.
    // Utility methods to get hours/minutes/seconds
    // from total time given in seconds.
    // Gets components for hr:min:sec string
    public int hoursFromTotal(int totalSeconds) {
        float fltHrs = totalSeconds / 3600;
        return (int) Math.floor(fltHrs);
    }

    public int minutesFromTotal(int totalSeconds) {
        float nsecs = hoursFromTotal(totalSeconds) * 3600;
        float secsleft = totalSeconds - nsecs;
        float fltMins = secsleft / 60;
        return (int)Math.floor(fltMins);
    }

    public int secondsFromTotal(int totalSeconds) {
        float fltSecs = totalSeconds - (hoursFromTotal(totalSeconds) * 3600)
                                     - (minutesFromTotal(totalSeconds) * 60);
        return (int)Math.floor(fltSecs);
    }

} // end RunEntry class
